<?php

class Common_model extends CI_Model
{

    private $_table = '';

    public function __construct()
    {
        parent::__construct();
    }

    /*
     * @todo get by id
     */

    function getByID($conditions = array())
    {
        if (count($conditions) > 0)
            $this->db->where($conditions);
        $this->db->from($this->_table);
        $this->db->select();
        $result = $this->db->get();
        return $result;
    }

    /*
     * @todo get one id
     */

    function getOneID($conditions = array(), $orderby = array())
    {
        //Check for Condition
        if (count($conditions) > 0)
            $this->db->where($conditions);

        //Check for Order by
        if (is_array($orderby) and count($orderby) > 0)
            $this->db->order_by($orderby [0], $orderby [1]);
        $this->db->from($this->_table);
        $this->db->select();
        $result = $this->db->get();
        $row = $result->first_row();
        return $row;
    }

    /*
     * @todo update
     */

    function updateData($updateKey = array(), $updateData = array())
    {
        $this->db->update($this->_table, $updateData, $updateKey);
    }

    /*
     * @todo delete
     */

    function deleteData($conditions = array())
    {
        if (count($conditions) > 0)
            $this->db->where($conditions);
        $this->db->delete($this->_table);
    }

    /*
     * @todo insert
     */

    function insertData($insertData = array())
    {
        $this->db->insert($this->_table, $insertData);
        $last = $this->db->insert_id();
        return $last;
    }

}
